package com.sunxueqi.project.system.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sunxueqi.common.constant.StatusConstants;
import com.sunxueqi.common.utils.KeyGenerate;
import com.sunxueqi.common.utils.SecurityUtils;
import com.sunxueqi.project.system.dao.LinkMapper;
import com.sunxueqi.project.system.service.ILinkService;
import com.sunxueqi.project.system.vo.Link;

@Service
public class LinkServiceImpl implements ILinkService{
	
	@Autowired
	private LinkMapper linkMapper;
	
	@Override
	public List<Link> selectLinkList(Link Link) {
		Link.setDeleteStatus(StatusConstants.NORMAL);
		return linkMapper.selectList(Link);
	}

	@Override
	public int add(Link Link) {
		Link.setId(KeyGenerate.getKeyId());
		Link.setDeleteStatus(StatusConstants.NORMAL);
		Link.setCreateBy(SecurityUtils.getLoginUserId());
		Link.setCreateTime(new Timestamp(System.currentTimeMillis()));
		return linkMapper.insert(Link);
	}

	@Override
	public int deleteLinkByIds(String[] idArray) {
		int result = 0;
		for(String id: idArray) {
			Link Link = new Link();
			Link.setId(id);
			Link.setDeleteStatus(StatusConstants.DELETED);
			Link.setDeleteTime(new Timestamp(System.currentTimeMillis()));
			Link.setDeleteBy(SecurityUtils.getLoginUserId());
			int count = linkMapper.updateByPrimaryKey(Link);
			result += count;
		}
		return result;
	}

	@Override
	public int updateLink(Link Link) {
		Link.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		Link.setUpdateBy(SecurityUtils.getLoginUserId());
		int count = linkMapper.updateByPrimaryKey(Link);
		return count;
	}

	@Override
	public int changeStatus(Link Link) {
		return linkMapper.updateByPrimaryKey(Link);
	}
}
